package cn.tedu.movie.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SeatMapper {
    @Select("SELECT s.rowcol\n" +
            "FROM seat s\n" +
            "LEFT JOIN `order` o ON s.order_id=o.id\n" +
            "LEFT JOIN `session` se ON o.session_id=se.id\n" +
            "WHERE se.id=#{id}")
    List<String> selectSeat(int id);
    @Insert("insert into seat values(null,#{orderId},#{seatNo})")
    void insert(Integer orderId,String seatNo);
    @Delete("delete from seat where order_id=#{orderId}")
    int deleteSeatByOrderId(int orderId);
    @Select("select rowcol from `seat` where order_id=#{id} order by id")
    List<String> getSeats(Integer id);
    @Select("SELECT COUNT(*) FROM `session` s,`seat` seat,`order` o\n" +
            "WHERE s.id=o.session_id AND seat.order_id=o.id\n" +
            "AND seat.rowcol=#{seatNo} AND s.id=#{sessionId}")
    int checkSeat(Integer sessionId ,String seatNo);
}
